package com.axzhengxin.platform.financeProduct.controller;

import java.util.List;

import com.axzhengxin.platform.business.domain.ProductArea;
import com.axzhengxin.platform.financeProduct.domain.AhCityDistrict;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.axzhengxin.platform.financeProduct.domain.FspFinanceProduct;
import com.axzhengxin.platform.financeProduct.service.IFspFinanceProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 金融机构发布产品Controller
 * 
 * @author axzhengxin
 * @date 2021-03-11
 */
@RestController
@RequestMapping("/financeProduct/product")
public class FspFinanceProductController extends BaseController
{
    @Autowired
    private IFspFinanceProductService fspFinanceProductService;

    /**
     * 查询金融机构发布产品列表
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(FspFinanceProduct fspFinanceProduct)
    {
        startPage();
        List<FspFinanceProduct> list = fspFinanceProductService.selectFspFinanceProductList(fspFinanceProduct);
        return getDataTable(list);
    }

    /**
     * 导出金融机构发布产品列表
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:export')")
    @Log(title = "金融机构发布产品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FspFinanceProduct fspFinanceProduct)
    {
        List<FspFinanceProduct> list = fspFinanceProductService.selectFspFinanceProductList(fspFinanceProduct);
        ExcelUtil<FspFinanceProduct> util = new ExcelUtil<FspFinanceProduct>(FspFinanceProduct.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 获取金融机构发布产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:query')")
    @GetMapping(value = "/{fprFlowno}")
    public AjaxResult getInfo(@PathVariable("fprFlowno") String fprFlowno)
    {
        return AjaxResult.success(fspFinanceProductService.selectFspFinanceProductById(fprFlowno));
    }

    /**
     * 新增金融机构发布产品
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:add')")
    @Log(title = "金融机构发布产品", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody FspFinanceProduct fspFinanceProduct)
    {
        return toAjax(fspFinanceProductService.insertFspFinanceProduct(fspFinanceProduct));
    }

    /**
     * 修改金融机构发布产品
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:edit')")
    @Log(title = "金融机构发布产品", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping
    public AjaxResult edit(@RequestBody FspFinanceProduct fspFinanceProduct)
    {
        return toAjax(fspFinanceProductService.updateFspFinanceProduct(fspFinanceProduct));
    }

    /**
     * 删除金融机构发布产品
     */
    @PreAuthorize("@ss.hasPermi('financeProduct:product:remove')")
    @Log(title = "金融机构发布产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fprFlownos}")
    public AjaxResult remove(@PathVariable String[] fprFlownos)
    {
        return toAjax(fspFinanceProductService.deleteFspFinanceProductByIds(fprFlownos));
    }

    /**
     * 产品下拉框
     * @return
     */
    @RequestMapping("/getList")
    public List<FspFinanceProduct> getList()
    {
        return fspFinanceProductService.getList();
    }

   /* @RequestMapping("/getTreeArea")
    public AjaxResult getTreeArea(){
        *//*List<AhCityDistrict> productAreas = fspFinanceProductService.selectAreaList();
        return AjaxResult.success(fspFinanceProductService.buildAreaTreeSelect(productAreas));*//*
        return AjaxResult.success();
    }*/
}
